import { createApp } from 'vue'
import Message from '@/components/message.vue'
import ElementPlus from 'element-plus'
import 'element-ui/lib/theme-chalk/index.css'
export type MessageType = 'success' | 'failed' | 'default'

const createMessage = (check: boolean, type: MessageType, timeout = 3000) => {
  const messageInstance = createApp(Message, {
    check
  })
  messageInstance.use(ElementPlus)
  const mountNode = document.createElement('div')
  document.body.appendChild(mountNode)
  messageInstance.mount(mountNode)
  setTimeout(() => {
    messageInstance.unmount()
    document.body.removeChild(mountNode)
  }, timeout)
}

export default createMessage
